home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / list / list.c next >
C/C++ Source or Header  |  1989-01-17  |  907b  |  49 lines

  1. #include <\c\include\stdio.h>
  2. #define MAXWORD 100
  3.  
  4. /* Source is from Advanced C by H. Schildt 1988. */
  5. main()
  6. {
  7.     char *find_next(), word[MAXWORD];
  8.     int char_cnt=0, word_cnt = 0, word_length = 0;
  9.  
  10.     while (find_next(word) != NULL)
  11.     {
  12.         capitalize(word);
  13.         ++word_cnt;
  14.         word_length = strlen(word);
  15.         char_cnt += word_length;
  16.         printf("\n%12d       %s", word_length, word);
  17.     }
  18.     printf("\n\n%12d  characters in %d words\n\n", char_cnt, word_cnt);
  19. }
  20.  
  21. char *find_next(word)
  22. char  word[];
  23. {
  24.     int c,i;
  25.  
  26.     while ((c = getchar()) == ' ' || c=='\n' || c == '\t');
  27.         if (c != EOF)
  28.         {
  29.             i =0;
  30.             while (c != ' ' && c != '\n' && c != '\t' && c != EOF)
  31.             {
  32.                 word[i++] = c;
  33.                 c = getchar();
  34.             }
  35.             word[i] = '\0';
  36.             return (word);
  37.         }
  38.         else
  39.             return (NULL);
  40. }
  41.  
  42. capitalize (p)
  43. char *p;
  44. {
  45.     for (; *p != '\0'; ++p)
  46.         if ('a' <= *p && *p <= 'z')
  47.             *p += 'A' - 'a';
  48. }
  49.